package company.tx1;

import java.util.*;

public class Tx3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // n个数
        int n = sc.nextInt();
        // 前k大 前k小
        int k = sc.nextInt();
        sc.nextLine();
        TreeMap<String, Integer> dict = new TreeMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.nextLine();
            dict.put(s, dict.getOrDefault(s, 0) + 1);
        }
        NavigableMap<String, Integer> map = dict.descendingMap();
        System.out.println(map);
        List<String> list = new ArrayList<>();
        int num = k;
        for (Map.Entry<String, Integer> e : map.entrySet()) {
            Integer value = e.getValue();
            if (num > value) {
                list.add(e.getKey() + " " + e.getValue());
                num -= e.getValue();
            } else {
                list.add(e.getKey() + " " + num);
                break;
            }
        }
        num = k;
        for (Map.Entry<String, Integer> e : dict.entrySet()) {
            Integer value = e.getValue();
            if (num > value) {
                list.add(e.getKey() + " " + e.getValue());
                num -= e.getValue();
            } else {
                list.add(e.getKey() + " " + num);
                break;
            }
        }

        System.out.println(list);
    }
}
